package com.qf.hmadmin.sys.user.service.impl;

import com.qf.entity.sys.SysUser;
import com.qf.hmadmin.sys.user.dao.SysUserDao;
import com.qf.hmadmin.sys.user.param.LoginParam;
import com.qf.hmadmin.sys.user.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Resource
    private SysUserDao sysUserDao;

    @Override
    public SysUser login(LoginParam loginParam) {

        SysUser sysUser = sysUserDao.selectByUsername(loginParam.getUsername());

        if (sysUser == null){
            throw  new RuntimeException("用户名或者密码错误");
        }
        if (loginParam.getUsername() == null || loginParam.getPassword() == null){
            throw  new RuntimeException("用户名或者密码为空");
        }
        if (!sysUser.getUsername().equals(loginParam.getUsername())){
            throw  new RuntimeException("用户名为空");
        }
if (!sysUser.getPassword().equals(loginParam.getPassword())){
    throw  new RuntimeException("密码错误");
}

        return sysUser;
    }
}
